#include "unicode.h"
#include <cstdint>
#include <vector>
#include "doctest.h"


TEST_CASE("[getByteNumOfEncodeUtf8]") {
    SUBCASE("字") {
        auto res = getByteNumOfEncodeUtf8(0x5b57);
        CHECK(res == 3);
    }
    SUBCASE("十") {
        auto res = getByteNumOfEncodeUtf8(0x5341);
        CHECK(res == 3);
    }
    SUBCASE("d") {
        auto res = getByteNumOfEncodeUtf8(0x64);
        CHECK(res == 1);
    }
}

TEST_CASE("[getByteNumOfDecodeUtf8]") {
    SUBCASE("字") {
        auto res = getByteNumOfDecodeUtf8(0xe5);
        CHECK(res == 3);
    }
    SUBCASE("d") {
        auto res = getByteNumOfEncodeUtf8(0x64);
        CHECK(res == 1);
    }
}

TEST_CASE("[encodeToUtf8]") {
    SUBCASE("字") {
        auto buf = std::vector<uint8_t>(getByteNumOfEncodeUtf8(0x5b57));
        auto buf_right = std::vector<uint8_t>{0xe5, 0xad,0x97};
        auto res = encodeToUtf8(0x5b57, buf);
        CHECK(buf == buf_right);
    }
    SUBCASE("十") {
        auto buf = std::vector<uint8_t>(getByteNumOfEncodeUtf8(0x5341));
        auto buf_right = std::vector<uint8_t>{0xe5, 0x8d, 0x81};
        auto res = encodeToUtf8(0x5341, buf);
        CHECK(buf == buf_right);
    }
    SUBCASE("d") {
        auto buf = std::vector<uint8_t>(getByteNumOfEncodeUtf8(0x64));
        auto buf_right = std::vector<uint8_t>{0x64};
        auto res = encodeToUtf8(0x64, buf);
        CHECK(buf == buf_right);
    }
}

TEST_CASE("[decodeFromUtf8]") {
    SUBCASE("字") {
        auto buf = std::vector<uint8_t>{0xe5, 0xad,0x97};
        auto res = decodeFromUtf8(buf);
        CHECK(res == 0x5b57);
    }
    SUBCASE("十") {
        auto buf = std::vector<uint8_t>{0xe5, 0x8d, 0x81};
        auto res = decodeFromUtf8(buf);
        CHECK(res == 0x5341);
    }
    SUBCASE("d") {
        auto buf = std::vector<uint8_t>{0x64};
        auto res = decodeFromUtf8(buf);
        CHECK(res == 0x64);
    }
}